package com.ruoyi.fantasy.service.impl;

import java.util.List;
import java.util.Map;

import com.ruoyi.fantasy.common.WorldInit;
import com.ruoyi.system.domain.SysDictData;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.service.ISysDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.fantasy.mapper.FantasyNoticeMapper;
import com.huanzhidadi.fantasy.bean.domain.FantasyNotice;
import com.ruoyi.fantasy.service.IFantasyNoticeService;
import com.ruoyi.common.core.text.Convert;

import javax.annotation.Resource;

/**
 * 公告 服务层实现
 * 
 * @author ruoyi
 * @date 2018-12-23
 */
@Service
public class FantasyNoticeServiceImpl implements IFantasyNoticeService 
{
	@Resource
	private FantasyNoticeMapper fantasyNoticeMapper;
	@Autowired
	private ISysDictDataService dictDataService;
	/**
     * 查询公告信息
     * 
     * @param noticeId 公告ID
     * @return 公告信息
     */
    @Override
	public FantasyNotice selectFantasyNoticeById(Integer noticeId)
	{
	    return fantasyNoticeMapper.selectFantasyNoticeById(noticeId);
	}
	
	/**
     * 查询公告列表
     * 
     * @param fantasyNotice 公告信息
     * @return 公告集合
     */
	@Override
	public List<FantasyNotice> selectFantasyNoticeList(FantasyNotice fantasyNotice)
	{
	    return fantasyNoticeMapper.selectFantasyNoticeList(fantasyNotice);
	}
	
    /**
     * 新增公告
     * 
     * @param fantasyNotice 公告信息
     * @return 结果
     */
	@Override
	public int insertFantasyNotice(FantasyNotice fantasyNotice)
	{
	    return fantasyNoticeMapper.insertFantasyNotice(fantasyNotice);
	}
	
	/**
     * 修改公告
     * 
     * @param fantasyNotice 公告信息
     * @return 结果
     */
	@Override
	public int updateFantasyNotice(FantasyNotice fantasyNotice)
	{
	    return fantasyNoticeMapper.updateFantasyNotice(fantasyNotice);
	}

	/**
     * 删除公告对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteFantasyNoticeByIds(String ids)
	{
		return fantasyNoticeMapper.deleteFantasyNoticeByIds(Convert.toStrArray(ids));
	}

	@Override
	public void transforData(List<FantasyNotice> list) {
		Map<String, SysUser> sysUserMap = WorldInit.sysUserMap;
		List<SysDictData> sysDictData = dictDataService.selectDictDataByType("fantasy_notice_type");
		for (FantasyNotice notice : list) {
			if (notice.getCreateBy() != null) {
				if (sysUserMap.get(notice.getCreateBy()) != null) {
					notice.setCreateBy(sysUserMap.get(notice.getCreateBy()).getUserName());
				} else {
					notice.setCreateBy("系统管理员");
				}
			}
			if (notice.getUpdateBy() != null) {
				if (sysUserMap.get(notice.getUpdateBy()) != null) {
					notice.setUpdateBy((sysUserMap.get(notice.getUpdateBy()).getUserName()));
				} else {
					notice.setUpdateBy("系统管理员");
				}
			}
			//禁用标记
			if (notice.getDelFlag().equals("0")) {
				notice.setDelFlag("正常");
			} else if (notice.getDelFlag().equals("1")) {
				notice.setDelFlag("禁用");
			}
			//公告类型
			for (SysDictData dict : sysDictData) {
				if (dict.getDictValue().equals(notice.getNoticeType())) {
					//notice.setNoticeCssStyle(dict.getCssClass());
					notice.setNoticeType("<span style='" + dict.getCssClass() + "'>" + dict.getDictLabel() + "</span>");
					break;
				}
			}
			//公告颜色
			//notice.setNoticeColor("<span style='color:" + notice.getNoticeColor() + "'>公告颜色</span>");
		}

	}

	@Override
	public int disableFantasyNoticeByIds(String ids) {
		return fantasyNoticeMapper.disableFantasyNoticeByIds(Convert.toStrArray(ids));
	}

	@Override
	public int restoreFantasyNoticeByIds(String ids) {
		return fantasyNoticeMapper.restoreFantasyNoticeByIds(Convert.toStrArray(ids));
	}

}
